package com.zj.ecology;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.zj.base.refresh.constance.RefreshState;
import com.zj.base.refresh.header.BaseHeader;
import com.zj.base.refresh.interfaces.RefreshLayoutIn;
import com.zj.base.refresh.views.RefreshLayout;

/**
 * Created by zhaojie on 2018/4/2.
 */

public class BatteryHeader extends BaseHeader {

    private BatteryView batteryView;

    public BatteryHeader(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public BatteryHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void initView(Context context) {
        addView(batteryView = new BatteryView(context));
        RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        rlp.addRule(CENTER_IN_PARENT);
        batteryView.setLayoutParams(rlp);
    }

    @Override
    public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {
        super.onMoving(isDragging, percent, offset, height, maxDragHeight);
        batteryView.setBattery(percent);
    }

    @Override
    public int onFinish(@NonNull RefreshLayoutIn refreshLayout, boolean success) {
        return super.onFinish(refreshLayout, success);
    }

    @Override
    public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {


        super.onStateChanged(refreshLayout, oldState, newState);

    }
}
